package com.springcloud.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springcloud.dao.TaskExeDao;
import com.springcloud.model.TaskModel;
import com.springcloud.service.TaskExeService;
import com.springcloud.utils.ConstantUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class TaskExeServiceImpl extends ServiceImpl<TaskExeDao, TaskModel> implements TaskExeService {
    @Resource
    private TaskExeDao taskExeDao;

    @Override
    public List<TaskModel> getTaskInfo(TaskModel model){
        QueryWrapper<TaskModel> wrapper=new QueryWrapper<>();
        wrapper.select("*")
                .like(model.getTaskNo()!=null&&model.getTaskNo().length()>0, "taskNo",model.getTaskNo())
                .like(model.getOperateType()!=null ,"operateType",model.getOperateType())
                .like(model.getBinnoFrom()!=null,"binnoFrom",model.getBinnoFrom())
                .like(model.getBinnoTo()!=null,"binnoTo",model.getBinnoTo())
                .like(model.getTaskState()!=null,"taskState",model.getTaskState())
                .like(model.getTaskTime()!=null,"taskTime",model.getTaskTime());
        return taskExeDao.selectList(wrapper);

    }

    @Override
    public List<TaskModel> refreshTask() {
       QueryWrapper<TaskModel> wrapper=new QueryWrapper<>();
        wrapper.select("*");
        return taskExeDao.selectList(wrapper);
    }

    @Override
    public TaskModel getOneTask(String taskNo) {
        QueryWrapper<TaskModel> taskWrapper=new QueryWrapper<>();
        taskWrapper.select("*").eq(ConstantUtil.Task.TASKNO,taskNo);
        return taskExeDao.selectOne(taskWrapper);
    }

    @Override
    public void updateTask(TaskModel task) {
        UpdateWrapper<TaskModel> wrapper=new UpdateWrapper<>();
        wrapper.eq(ConstantUtil.Task.TASKNO,task.getTaskNo()).set("taskState",task.getTaskState());
        taskExeDao.update(task,wrapper);
    }


}
